import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    code: 'login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    code: '404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    code: 'home',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    code: 'system',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [{
      path: 'user',
      name: '用户管理',
      component: () => import('@/views/system/user/index'),
      meta: { title: '用户管理', icon: 'table' }
    }, {
      path: 'role',
      name: '角色管理',
      component: () => import('@/views/system/role/index'),
      meta: { title: '角色管理', icon: 'table' }
    }, {
      path: 'department',
      name: '部门管理',
      component: () => import('@/views/system/department/index'),
      meta: { title: '部门管理', icon: 'table' }
    }, {
      path: 'dictionary',
      name: '字典管理',
      component: () => import('@/views/system/dictionary/index'),
      meta: { title: '字典管理', icon: 'table' }
    }, {
      path: 'logs',
      name: '日志管理',
      component: () => import('@/views/system/logs/index'),
      meta: { title: '日志管理', icon: 'table' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/dynamic',
    name: '动态管理',
    code: 'dynamic',
    meta: { title: '动态管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '动态管理',
        component: () => import('@/views/dynamic/index'),
        meta: { title: '动态列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/association',
    component: Layout,
    redirect: '/example/association',
    name: '公会管理',
    code: 'dynamic',
    meta: { title: '公会管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '公会管理',
        component: () => import('@/views/association/index'),
        meta: { title: '公会管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/shop',
    component: Layout,
    redirect: '/example/shop',
    name: '商城管理',
    code: 'circle',
    meta: { title: '商城管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '商城管理',
        component: () => import('@/views/shop/index'),
        meta: { title: '商城管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/withdrawal',
    component: Layout,
    redirect: '/example/withdrawal',
    name: '提现管理',
    code: 'topic',
    meta: { title: '提现管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '提现管理',
        component: () => import('@/views/withdrawal/index'),
        meta: { title: '提现管理', icon: 'table' }
      }
    ]
  },

  {
    path: '/party',
    component: Layout,
    redirect: '/example/party',
    name: '房间管理',
    code: 'dynamic',
    meta: { title: '房间管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'partyList',
        name: '房间列表',
        component: () => import('@/views/party/index'),
        meta: { title: '房间列表', icon: 'table' }
      },
      {
        path: 'giveGiftList',
        name: '送礼物记录',
        component: () => import('@/views/party/giveGiftList/index'),
        meta: { title: '送礼物记录', icon: 'table' }
      },
      {
        path: 'giftList',
        name: '礼物列表',
        component: () => import('@/views/gift/index'),
        meta: { title: '礼物列表', icon: 'table' }
      },
      {
        path: 'lottery',
        name: '活动记录',
        component: () => import('@/views/lottery/index'),
        meta: { title: '活动记录', icon: 'table' }
      },
      {
        path: 'lotteryList',
        name: '活动管理',
        component: () => import('@/views/lottery/lotteryRecord/index'),
        meta: { title: '活动管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/party',
    component: Layout,
    redirect: '/example/party',
    name: '公会管理',
    code: 'circle',
    meta: { title: '房间管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'partyList',
        name: '房间列表',
        component: () => import('@/views/party/index'),
        meta: { title: '房间列表', icon: 'table' }
      }, {
        path: 'userList',
        name: '成员列表',
        component: () => import('@/views/party/partyUser/index'),
        meta: { title: '成员列表', icon: 'table' }
      }
    ]
  },
  {
    path: '/recharge',
    component: Layout,
    redirect: '/example/recharge',
    name: '充值管理',
    code: 'topic',
    meta: { title: '充值管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: '充值管理',
        component: () => import('@/views/recharge/index'),
        meta: { title: '充值管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/student',
    component: Layout,
    code: 'student',
    children: [
      {
        path: 'index',
        name: '下级管理',
        component: () => import('@/views/student/index'),
        meta: { title: '下级管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/circle',
    code: 'dynamic',
    component: Layout,
    children: [
      {
        path: 'index',
        name: '圈子管理',
        component: () => import('@/views/circle/index'),
        meta: { title: '圈子管理', icon: 'form' }
      }
    ]
  }, {
    path: '/user',
    code: 'user',
    name: '用户管理',
    meta: { title: '用户管理', icon: 'el-icon-s-help' },
    component: Layout,
    children: [
      {
        path: 'index',
        name: '用户列表',
        component: () => import('@/views/user/index'),
        meta: { title: '用户管理', icon: 'form' }
      }, {
        path: 'testAccount',
        name: '测试账号',
        component: () => import('@/views/user/test/index'),
        meta: { title: '测试账号', icon: 'form' }
      },
      {
        path: 'systemBalanceList',
        name: '系统修改金币记录',
        component: () => import('@/views/user/updateBalanceList/index'),
        meta: { title: '系统修改金币记录', icon: 'table' }
      },
      {
        path: 'userSkill',
        name: '用户技能管理',
        component: () => import('@/views/user/userSkill/index'),
        meta: { title: '用户技能管理', icon: 'form' }
      }
    ]
  }, {
    path: '/topic',
    component: Layout,
    redirect: '/topic',
    code: 'topic',
    name: '话题管理',
    meta: { title: '话题管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'index',
        name: '话题管理',
        component: () => import('@/views/topic/index'),
        meta: { title: '话题管理', icon: 'form' }
      }, {
        path: 'category',
        name: '话题分类管理',
        component: () => import('@/views/topic/category/index'),
        meta: { title: '话题分类管理', icon: 'form' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
